<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自动清空宿舍数据</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
            line-height: 1.6;
            text-align: center;
        }
        .container {
            background-color: #f5f5f5;
            padding: 40px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            margin-top: 50px;
        }
        h1 {
            color: #333;
        }
        .success {
            color: #4CAF50;
            font-size: 18px;
            margin: 20px 0;
        }
        .error {
            color: #f44336;
            font-size: 18px;
            margin: 20px 0;
        }
        .log {
            background-color: #222;
            color: #0f0;
            padding: 15px;
            border-radius: 4px;
            margin-top: 20px;
            font-family: monospace;
            text-align: left;
            height: 200px;
            overflow-y: auto;
        }
        button {
            background-color: #008CBA;
            color: white;
            border: none;
            padding: 12px 24px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 20px 0;
            cursor: pointer;
            border-radius: 4px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>宿舍数据自动清空工具</h1>
        <p>页面正在自动清空宿舍数据，请稍候...</p>
        <div id="result"></div>
        <div class="log" id="logs"></div>
        <button onclick="location.reload()">重新清空数据</button>
    </div>

    <script>
        // 日志输出函数
        function log(message) {
            const logs = document.getElementById('logs');
            const logItem = document.createElement('div');
            logItem.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
            logs.appendChild(logItem);
            logs.scrollTop = logs.scrollHeight;
        }

        // 清空宿舍数据的函数
        function clearDormitoryData() {
            const resultDiv = document.getElementById('result');
            
            try {
                log('开始检查localStorage环境...');
                if (typeof localStorage === 'undefined') {
                    throw new Error('浏览器不支持localStorage');
                }
                
                log('localStorage环境正常');
                log('开始清空宿舍数据...');
                
                // 清空所有可能的宿舍数据键
                const keysToRemove = [
                    'dormitoryStorage',
                    'mock_dormitories',
                    'dormitories',
                    'dorm_data',
                    'dormitories_data'
                ];
                
                keysToRemove.forEach(key => {
                    if (localStorage.getItem(key)) {
                        localStorage.removeItem(key);
                        log(`✓ 已清空: ${key}`);
                    } else {
                        log(`- 不存在: ${key}`);
                    }
                });
                
                log('宿舍数据清空操作完成');
                
                // 显示成功信息
                resultDiv.className = 'success';
                resultDiv.textContent = '✓ 宿舍数据已成功清空！';
                
            } catch (error) {
                log(`✗ 清空数据失败: ${error.message}`);
                
                // 显示错误信息
                resultDiv.className = 'error';
                resultDiv.textContent = `✗ 清空数据失败: ${error.message}`;
            }
        }

        // 页面加载后自动执行清空操作
        window.onload = function() {
            log('页面加载完成，开始自动清空宿舍数据');
            clearDormitoryData();
        };
    </script>
</body>
</html>